package com.qyj.spring_boot_02.controller;

import com.alibaba.fastjson.JSONObject;
import com.qyj.spring_boot_02.bean.LocationDateXiaoLiang;
import com.qyj.spring_boot_02.service.DataService;
import com.qyj.spring_boot_02.util.MyParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/data")
public class DataContraller {
    @Autowired
    DataService dataService;
    @GetMapping("/shang")
    public JSONObject getspplCountNum(){
        return dataService.getShangPing();
    }
    @GetMapping("/duizhaolist")
    public JSONObject getNameSkuClassList(){
        return dataService.getNameSkuClassList();
    }
    @GetMapping("/userpingluntime")
    public JSONObject getUserPingLunTime(@RequestParam(value = "month",defaultValue = "0",required = false) Integer month,
                                         @RequestParam(value = "skuClass",defaultValue = "666",required = false) String skuClass){
        if (month == null) {
            month = 0;
        }
        // 检查month是否为负数
        if (month < 0) {
            // 直接创建一个JSONObject实例，而不是从字符串中解析
            return MyParamUtil.reParamPageFun();
        }
        if (skuClass.equals("666")){
            return dataService.getTimeCount(month);
        }else{
            return dataService.getTimeCountWithSkuClass(skuClass);
        }
    }
    @GetMapping("/jiagequjianCount")
    public JSONObject getPriceRangeCount(){
        return dataService.getPriceRangeCount();
    }
    @GetMapping("/peizhiKeyWord")
    public JSONObject getPeizhiKeyWordCount(@RequestParam(value = "page", required = false) Integer page ){
        if(page == null){
            page = 1;
        }
        if(page < 0){
            return MyParamUtil.reParamPageFun();
        }
        log.info("getPeizhiKeyWord成功");
        return dataService.getPeizhiKeyWord(page);
    }
    @GetMapping("/pinglunkeyword")
    public JSONObject getPingLunKeyWord(@RequestParam(value = "page", required = false) Integer page ){
        if(page == null){
            page = 1;
        }
        if(page < 0){
            return MyParamUtil.reParamPageFun();
        }
        return dataService.getPingLunKeyWord(page);
    }
    @GetMapping("/fenleidepinglunCount")
    public JSONObject getFenLeiPingLunCoun(){
        return dataService.getPingPaiPingLunCount();
    }
    @GetMapping("/skuhaopingavg")
    public JSONObject getSkuHaoPingAvg(){
        return dataService.getSkuHaoPingAvg();
    }
    @GetMapping("/pingpaiXiaoliang")
    public JSONObject getPingPaiXiaoLiang(){
        return dataService.getSkuXiaoCountService();
    }
    @GetMapping("/LocationCount")
    public JSONObject getLocationCount(@RequestParam(value = "year",defaultValue = "0",required = false) Integer year){
        return dataService.getLocationCountService(year);
    }
    @GetMapping("/LocationCountWithYearJiDu")
    public JSONObject getLocationCountYearQD(@RequestParam(value = "year",defaultValue = "2023",required = false) Integer year,
                                             @RequestParam(value = "jidu",defaultValue = "春季",required = false) String qd){
        return dataService.getLocationCountQd(year,qd);
    }
    @GetMapping("/getDataFenXiWithLocationDateXiaoLiang")
    public List<LocationDateXiaoLiang> getDataFenXiWithLocationDateXiaoLiang(){
        return dataService.getDataFenXiWithLocationDateXiaoLiang();
    }
    @GetMapping("/getPinPaiXiaoLiang")
    public JSONObject getPinPaiXiaoLiangContr(@RequestParam(value = "year",defaultValue = "2023",required = false) Integer year,
                                              @RequestParam(value = "jidu",defaultValue = "春季",required = false) String jidu){
        return dataService.getPinPaiXiaoLiangService(year,jidu);
    }
    @GetMapping("/getCiyunData")
    public JSONObject getCiyunData(@RequestParam(value = "year",defaultValue = "2024",required = false) String year,
                                   @RequestParam(value = "jidu",defaultValue = "春季",required = false) String jidu,
                                   @RequestParam(value = "page",defaultValue = "0",required = false) Integer page,
                                   @RequestParam(value = "pageNum",defaultValue = "0",required = false) Integer pageNum){
        return dataService.getShiYinWithTheTimeService(year, jidu, page, pageNum);
    }
    @GetMapping("/keshihuaData")
    public JSONObject getkeshihuaData(){
        return dataService.getKeshihuaData();
    }
    @GetMapping("/jiageQUJianAnPinPai")
    public JSONObject getjiageQUJianAnPinPai(@RequestParam(value = "skuClass",defaultValue = "666", required = false) String skuClass){
        if (skuClass.equals("666")){
            return dataService.getNameSkuClassList();
        }
        return dataService.getjiageQUJianAnPinPaiService(skuClass);
    }
    @GetMapping("/getselectLocationWhere")
    public JSONObject getselectLocationWhereSkuClassBean(@RequestParam(value = "skuClass",defaultValue = "666",required = false) String skuClass ){
        if(skuClass.equals("666")){
            return dataService.getNameSkuClassList();
        }
        return dataService.getSelectLocationWhereSkuClassBeanListService(skuClass);
    }
    @GetMapping("/getSkuInfoProductWhere")
    public JSONObject getSkuInfoProductAll(@RequestParam(value = "skuClass",defaultValue = "A",required = false) String skuClass,
                                           @RequestParam(value = "page",defaultValue = "0",required = false) Integer page,
                                           @RequestParam(value = "pageNum",defaultValue = "1000",required = false) Integer pageNum){
        if (page < 0 || pageNum < 0){
            return null;
        }
        return dataService.getgetSkuInfoProductAll(skuClass,page*pageNum,pageNum);
    }
    @GetMapping("/getGetKeyWordBySkuClass")
    public JSONObject getGetKeyWordBySkuClass(@RequestParam(value = "skuClass",defaultValue = "A",required = false) String skuClass,
                                              @RequestParam(value = "page",defaultValue = "0",required = false) Integer page,
                                              @RequestParam(value = "pageNum",defaultValue = "20",required = false) Integer pageNum){
        if (page < 0 || pageNum < 0){
            return null;
        }
        return dataService.getGetKeyWordBySkuClassBean(skuClass, page, pageNum);
    }
    @GetMapping("/getSkuInfoWhereSkuClass")
    public JSONObject getSkuInfoWhereSkuClass(@RequestParam(value = "skuClass",defaultValue = "A",required = false) String skuClass,
                                              @RequestParam(value = "page",defaultValue = "0",required = false) Integer page,
                                              @RequestParam(value = "pageNum",defaultValue = "20",required = false) Integer pageNum){
        if (page < 0 || pageNum < 0){
            return null;
        }
        return dataService.getSkuInfoWhereSkuClassService(skuClass,page,pageNum);
    }
}
